package com.jzoom.zoom.admin.adapters;

import com.jzoom.zoom.dao.adapters.DataAdapter;
import org.apache.commons.lang3.StringUtils;

import java.util.Collections;
import java.util.LinkedHashSet;
import java.util.Set;

public class DataAdapters {


    public static class Set2StringAdapter implements DataAdapter<Set<String>,String>{

        @Override
        public String toDbValue(Set<String> strings) {
            if(strings==null)return null;
            return StringUtils.join(strings,",");
        }

        @Override
        public Set<String> toEntityValue(String s) {
            if(s==null)return null;
            Set<String> set = new LinkedHashSet<String>();
            Collections.addAll(set ,
                    StringUtils.split(s,",")
            );

            return set;
        }
    }

}
